package lesson02_udp;

import java.net.DatagramPacket;
import java.net.DatagramSocket;

//还是要等待客户端的连接
public class UdpServerDemo01 {
    public static void main(String[] args) throws  Exception {
        //开放端口
        DatagramSocket socket=new DatagramSocket(99);
        //接受数据包
        byte[] buffer=new byte[1024];
        DatagramPacket datagramPacket=new DatagramPacket(buffer,0,buffer.length);

        socket.receive(datagramPacket);//阻断接受

        System.out.println(datagramPacket.getAddress().getHostAddress());
        System.out.println(new String(datagramPacket.getData(),0,datagramPacket.getLength()));

        //关闭源
        socket.close();

    }
}
